var vm = new Vue({
    el: "#login",
    data: {
        userID: "",
        psw: "",
        verify1: "",
        Image: ["images/1.png",
            "images/2.png",
            "images/3.png",],
        verifyImageNum: [
            "13",
            "56",
            "14"
        ],
        index: 0
    },
    methods: {
        getID() {
            if (this.userID.length < 4) {
                if (this.userID.length == 0) {
                    alert("请输入用户名!");
                }
                else {
                    alert("用户名不小于4位！请重新输入!");
                }

            }
        },
        next: function () {

            if (this.index > this.Image.length - 2) {
                this.index = 0;
            }
            else {
                this.index++;
            }
        },
        verify: function () {
            this.getID();

            if (this.userID.length < 4) {
                if (this.userID.length == 0) {
                    alert("请输入用户名!");
                }
                else {
                    alert("用户名不小于4位！请重新输入!");
                }

            }
            else if (this.psw.length > 18 || this.psw.length < 4) {
                if (this.psw.length == 0) {
                    alert("请输入密码!");
                }
                else {
                    alert("密码要介于6-18位之间!");
                }
            }
            else if (this.verify1.length == 0) {
                alert("请输入验证码！")
            }
            else {
                if (this.verify1 == this.verifyImageNum[this.index]) {
                    axios.get('http://localhost:8080/s2/jdbc?userid=' + this.userID + '&password=' + this.psw)
                        .then(function (response) {
                            if (response.data === "登录成功") {
                                alert("登录成功!");
                                window.location.replace("manage.html");
                            }
                            // handle success
                            console.log(response);
                        })
                        .catch(function (error) {
                            // handle error
                            console.log(error);
                        })
                        .then(function () {
                            // always executed
                        });
                    // alert("验证码正确！");
                }
                else {
                    if (this.index > this.Image.length - 2) {
                        this.index = 0;
                    }
                    else {
                        this.index++;
                    }
                    alert("验证码错误!")
                }
            }

        }
    }
})
